package it.polimi.TravelDreamEAR.managedBeans;


import java.util.ArrayList;
import java.util.List;

import it.polimi.TravelDreamEAR.ejb.sessionBeans.HotelManager;
import it.polimi.TravelDreamEAR.ejb.sessionBeans.dto.*;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

@ManagedBean (name="hotelBean")
@RequestScoped
public class HotelBean {

	@EJB
	private HotelManager hotelManager;
	
	private HotelDTO hotelDTO;
	
	private List<HotelDTO> hotel;
	
	public HotelDTO getHotelDTO() {
		return hotelDTO;
	}

	public void setHotelDTO(HotelDTO hotelDTO) {
		this.hotelDTO = hotelDTO;
	}

	
	public HotelBean(){
		this.hotel = new ArrayList<HotelDTO>();
		this.hotelDTO= new HotelDTO();
	}

	public List<HotelDTO> getHotel() {
		this.setHotel();
		return hotel;
	}

	public void setHotel() {
		this.hotel = this.hotelDisponibili();
	}
	
	public List<HotelDTO> hotelDisponibili(){
		List<HotelDTO> hotels = hotelManager.trovaHotel();
		return hotels;
	}
	
	public String creazione(){	
		if(hotelManager.creazioneHotel(this.hotelDTO)==1)
			return "creaHotel.xhtml?faces-redirect=true";
		return "errore.hxtml?faces-redirect=true";
	}
	
	public String eliminazione(){
		if(hotelManager.eliminazioneHotel(this.hotelDTO)==1)
			return "eliminaHotel.xhtml?faces-redirect=true";		
		return "errore.hxtml?faces-redirect=true";
	}
}
